
#include "file_path.h"


static  FileListHandle video_photo_list = NULL;

static  int  file_search_mode = 0;
static  int  file_total_num   = 0;

int file_create_list(char * path)
{
	pFileList   filelist ;

	video_photo_list = file_list_create(VIDEO_PHOTO_MUSIC_FILE_LIST);

	if(!video_photo_list)
		return -1;

	log_i("path = %s\n",path);

	file_list_read_all_file(video_photo_list,path,0);
	
	filelist = (pFileList)(video_photo_list);

	log_i("file num = %d\n",filelist->filenum);

	file_total_num = filelist->filenum;

	return 0;
}


int file_get_total_num(void)
{
	return file_total_num;
}






int file_get_full_name(char * filename,int index)
{
	int ret = -1;
	
	FileInfo    fileinfo;
	pFileList   filelist ;

	if(!filename)
		return -1;

	if(!video_photo_list)
		return -1;

	if(!file_total_num)
		return -1;

	file_search_mode = video_para_get_playmode();

	switch(file_search_mode){
	case PLAY_MODE_ALL_LOOP:
	{

		break;
	}
	case PLAY_MODE_ONE_LOOP:
	{

		break;
	}
	case PLAY_MODE_RAND:
	{
		srand(time(NULL));
		if(file_total_num == 1)
		{
			index = 1;
		}
		else
		{
			index = rand()%file_total_num;
		}

		break;
	}
	case PLAY_MODE_ONCES:
	{

		break;
	}
	default:break;
	}

	
	ret = file_list_get_file(video_photo_list,index,&fileinfo);
	if(ret != 0){
		return -1;
	}

	file_get_fullname(filename,fileinfo.path,fileinfo.name);

	log_i("t:i:name=%d:%d:%s\n",file_total_num,index,filename);

	return 0;
}




int file_delete_list(void)
{

	if(video_photo_list){
		file_list_delete(video_photo_list);
		video_photo_list = NULL;
	}

	return 0;
}





